package com.rajaev.dtu.tractor.interfaces;


import com.github.pagehelper.PageInfo;
import com.rajaev.dtu.tractor.app.service.BatteryService;
import com.rajaev.dtu.tractor.domain.entity.UserInfo;
import com.rajaev.dtu.tractor.domain.vo.BatteryAllocationQueryVo;
import com.rajaev.dtu.tractor.domain.vo.BatteryAllocationVo;
import com.rajaev.dtu.tractor.infrastructure.helper.UserSecurityUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @Created with IDEA
 * @author: tianjie
 * @Date:2019/4/2
 * @Time:13:47
 */
@RestController
public class BatteryAllocateController {

    @Autowired
    BatteryService batteryService;

    @Autowired
    UserSecurityUtil userSecurityUtil;

    @GetMapping("battery/getAllocationList")
    public PageInfo<BatteryAllocationVo> pageQueryBatteryAllocations(BatteryAllocationQueryVo batteryAllocationQueryVo, HttpServletRequest request) {
        UserInfo userInfo = userSecurityUtil.getLoginUser(request).getUserInfo();
        batteryAllocationQueryVo.setCustomerUserId(userInfo.getId());
        return batteryService.pageQueryBatteryAllocateInfo(batteryAllocationQueryVo);
    }


    /**
     * 电池划拨到客户的接口
     * @param customerId
     * @param batteryId
     */
    @PostMapping("/battery/allocation")
    public void allocateBattery(Integer customerId,Integer batteryId){
        batteryService.batteryAllocate(customerId,batteryId);
    }

}
